package part2;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.PriorityQueue;

public class Board {
	int[][] boardValues;
	int[][] boardColors;        
	
	public Board(String fileName) {
		BufferedReader br = null;
		try {
			String currentLine;
			br = new BufferedReader(new FileReader(fileName));
			//Magic Number
			boardValues = new int[6][];
			boardColors = new int[6][6];
			// read in the txt file line by line, 
			for(int i=0;(currentLine = br.readLine()) != null; i++) {
						//split on whitespace
						String[] listInputs = currentLine.split("\\s+");
						boardValues[i] = new int[listInputs.length];
						for(int j =0;j<listInputs.length;j++){
							boardValues[i][j] = Integer.parseInt(listInputs[j]);
							boardColors[i][j] = 0;
						}
				}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
	}
	
	public Board(Board b) {
		boardValues = new int[6][6];
		boardColors = new int[6][6];
		for(int i =0; i< 6; i++){
			for(int j=0; j<6; j++){
				boardValues[i][j] = b.boardValues[i][j];
				boardColors[i][j] = b.boardColors[i][j];
			}
		}
	}

	//check if there are any possible moves left
	public boolean isFull(){
		for(int i =0; i < boardColors.length; i++){
			for(int j =0; j < boardColors[i].length; j++){
				if(boardColors[i][j] == 0)
					return false;
			}
		}
		return true;
	}
	public void print() {
		for(int i=0; i<boardColors.length; i++) {
			for(int j=0; j<boardColors[0].length; j++) {
				System.out.print(boardColors[i][j] + "/" + boardValues[i][j] + " ");
			}
			System.out.println();
		}
		System.out.println();
	}
	
	public String[][] getString(){
		String[][] ret = new String[6][6];
		for(int i=0; i<boardColors.length; i++) {
			for(int j=0; j<boardColors[0].length; j++) {
				ret[i][j]=(boardColors[i][j] + "/" + boardValues[i][j] + " ");
			}
		}
		return ret;
	}
	
	public int[] calcTotals() {
		int[] ret = new int[3];
		for(int i=0; i<boardColors.length; i++) {
			for(int j=0; j<boardColors[0].length; j++) {
				ret[boardColors[i][j]] += boardValues[i][j];
			}
		}
		return ret;
	}
}
